<template>
	<view>
		<view class="timeBox">
			<view class="time">
				<view class="example-body">
					<uni-datetime-picker type="date" :border="false" :clear-icon="false" v-model="single" :end="endtime" @change="change" /></view>
				<!-- <view class="time_rili" @click="show = true">
					<text>{{date}}</text>
					<image src="../../../static/rili.png" mode=""></image>
				</view>
				<u-calendar :show="show" @confirm="confirm" :minDate="maxDate"></u-calendar> -->
			</view>
		</view>

		<view class="listBox">
			<view class="" v-for="item in list.data" :key="item.look_date">
				<view class="item" v-for="ite in item.goods_list" :key="ite.id"  @click="jumpdetail(ite.id)">
					<view class="left">
						<image :src="ite.goods_image" mode=""></image>
					</view>
					<view class="right" style="flex-grow: 1;">
						<view class="rightTop">
							<view class="title">{{ite.goods_name}}</view>
							<view class="jifen">积分：{{ite.jifen}}分</view>
						</view>
						<view class="rightBottom flexbetween">
							<view class="rightBottomPrice">￥{{ite.price}}</view>
							<view class="rightBottomIcon" @click.stop="addCart(ite.id)"><image src="../../../static/smallIcon/gouwuche.png" mode=""></image></view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/commonFun/httpRequest.js");
	import conmon from '@/commonFun/conmon.js';
	// const d = new Date()
	// const year = d.getFullYear()
	// let month = d.getMonth() - 1
	// let months = d.getMonth() + 1
	// month = month < 10 ? `0${month}` : month
	// months = months < 10 ? `0${months}` : months
	// const date = d.getDate()
	export default {
	data() {
		return {
			getHistoryData: [],
			single: '' ,// 日期
			// 分页处理数据
			page: 1,
			limit: 12,
			list: {
				data: [],
			},
			show:false,
			// maxDate: `${year}-${month}-${date}`,
			date:'',
			endtime:Date.parse(new Date())
		};
	},
	onLoad() {
		this.init();
	},
	methods: {
		addCart(id){
			let _this = this;
			httpRequest.request('appapi/applet/goods/addCart','POST',{
				goods_id:id,
				goods_unit:0,
				goods_attr:0,
				number:1
			}).then(res => {
				if(res.code == 1){
					httpRequest.toast('添加成功')
				}else{
					httpRequest.toast(res.msg)
				}
			})
		},
		jumpdetail(id){
			uni.navigateTo({
				url:'/pages/index/commodityDetail/commodityDetail?id=' + id
			})
		},
		init(isPage, page) {
			let _this = this;
			httpRequest.request('appapi/applet/goods/getHistory', 'POST', {
				page: page || 1,
				limit: _this.limit,
				date: _this.date, //时间
			}, false, false, true).then(res => {
				if (res.code == 1) {
					let resList = res.data;
					let dataList = _this.list;
					if (isPage == true) {
						_this.list.data = dataList.data.concat(resList.list);
					} else {
						_this.list = resList;
						_this.list.data = resList.list;
					}
					console.log(_this.list.data,"shuju")
				}else{
					httpRequest.toast(res.msg);
				}
			}).catch(err => {
				httpRequest.toast(err.msg);
			})
		},
		onReachBottom() {
			let _this = this;
			let list = _this.list;
			let page = _this.page;
			if (list.lastpage <= page) {
				return false;
			}
			page++;
			_this.page = page;
			_this.init(true, page);
		},
		change(e) {
			console.log(e);
			this.date = e;
			this.init();
		},
	}
};
</script>

<style scoped lang="scss">
.listBox {
	padding: 0 30rpx 30rpx 30rpx;
	font-size: 0;
	.item {
		background-color: #ffffff;
		display: flex;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		padding:0 30rpx;
		.right {
			display: flex;
			justify-content: space-between;
			flex-direction: column;
			padding: 20rpx;
			.rightTop {
				font-family: PingFang SC;
				font-weight: 800;
				color: #333333;
				.title {
					font-size: 30rpx;
					margin-bottom: 16rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
				}
				.jifen {
					font-size: 28rpx;
				}
			}
			.rightBottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.rightBottomPrice {
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 800;
					color: #ff0000;
				}
				.rightBottomIcon {
					image {
						width: 30rpx;
						height: 27rpx;
					}
				}
			}
		}
		.left {
			image {
				width: 240rpx;
				height: 240rpx;
				border-radius: 20rpx 0px 0px 20rpx;
			}
		}
	}
}
.timeBox {
	padding: 20rpx 30rpx;
	.time {
		// background-color: #fff;
		border-radius: 60rpx;
		.time_rili{
			width: 250rpx;
			padding: 10rpx 20rpx;
			font-size: 36rpx;
			image{
				width: 30rpx;
				height: 30rpx;
				margin-left: 20rpx;
			}
		}
	}
	// background-color: rgb(246, 246, 246);
}
</style>
